package views;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JScrollPane;

import services.AvionesServices;
import services.ClientesServices;
import services.ConexionSql;

import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JMenu;




import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

import javax.swing.JMenuItem;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.JPanel;

import model.*;

import java.awt.Font;


import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JButton;

import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JMenu;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.swing.JMenuItem;

import java.awt.GridLayout;

import javax.swing.JPanel;

import java.awt.Font;

import javax.swing.SwingConstants;
import javax.swing.JTextField;

import java.awt.Color;



import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JScrollPane;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

import javax.swing.JMenu;

import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Vector;

import javax.swing.JMenuItem;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.JPanel;

import model.*;

import java.awt.Font;

import javax.swing.UIManager;
import javax.swing.SwingConstants;

import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.FlowLayout;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.BoxLayout;

import services.ClientesServices;

import java.awt.CardLayout;
import java.awt.SystemColor;
import java.awt.GridLayout;

import net.miginfocom.swing.MigLayout;

public class PanelVerAviones extends JPanel {

	private static final long serialVersionUID = 1L;
	private JTable table;


	public PanelVerAviones() {
		
		setLayout(new MigLayout("", "[496.00px,grow,fill]", "[][445px,center]"));
		  
		
		JLabel lblClientesActuales = new JLabel("Aviones Actuales");
		lblClientesActuales.setHorizontalAlignment(SwingConstants.CENTER);
		lblClientesActuales.setFont(new Font("Tahoma", Font.PLAIN, 16));
		lblClientesActuales.setBounds(32, 11, 171, 28);
		add(lblClientesActuales, "cell 0 0");

		
		// PARTICULAR

		JPanel panel = new JPanel();
		panel.setBounds(32, 50, 447, 439);// tamm
		add(panel, "cell 0 1,alignx left,aligny top");
	
		
		table =  new JTable();
		table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		JScrollPane tableSP = new JScrollPane(table);
		panel.add(tableSP);

		tableSP.setBorder(new EmptyBorder(5, 5, 5, 5));

		table.setModel(new DefaultTableModel(new Object[][] {}, new String[] {
				"ID", "Nombre", "P. Primera","P. Economica","P. Business" }) {
			Class[] columnTypes = new Class[] { Integer.class, String.class,
					Integer.class ,Integer.class,Integer.class};

			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
		});

		table.getTableHeader().setReorderingAllowed(false);// no reordenar
															// columnas
		table.setAutoResizeMode(JTable.WIDTH);// que ocupe todo lo del jpanel

		//CARGA AVIONES en AvionesActuales
		AvionesServices Av = new AvionesServices();
		List<Aviones> AvionesActuales = new ArrayList<Aviones>();
		
		
		 try {
			 AvionesActuales = Av.GetAvionesAll();
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		 
			 DefaultTableModel model = (DefaultTableModel) table.getModel();
		 for (int i = 0; i < AvionesActuales.size(); i++) {
			    Aviones temp = AvionesActuales.get(i);
		
			    Vector row = new Vector();
			    row.add(temp.getId());
			    row.add(temp.getNombre());
			    row.add(temp.getPasajerosprimera());
			    row.add(temp.getPasajeroseconomica());
			    row.add(temp.getPasajerosbusiness());
			    model.addRow(row);
			
			    
			    
			  //  table.add(new Object[]{temp.getId(),temp.getNombre(), temp.getPasajerosprimera(),temp.getPasajeroseconomica(),temp.getPasajerosbusiness()});
		 }
																					

	}

}





